﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace Twitter8N
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //delimited=length&
                Uri uri = new Uri("https://stream.twitter.com/1.1/statuses/filter.json?track=fuck");
                WebRequest http = HttpWebRequest.Create(uri);

                http.Credentials = new NetworkCredential("hav29A", "32choris");
                HttpWebResponse response = (HttpWebResponse)http.GetResponse();
                Stream stream = response.GetResponseStream();

                StreamReader sr = new StreamReader(stream);

                StreamWriter sw = File.AppendText("fuck.txt");

                string linea = "";
                while (null != (linea = sr.ReadLine()))
                {
                    Console.WriteLine(linea);

                    sw.WriteLine    (DateTime.Now.ToString() + "@@@" + linea);
                    sw.Flush        ();
                }
            }
            catch (UriFormatException e)
            {
                Console.WriteLine("Invalid URL");
            }
            catch (IOException e)
            {
                Console.WriteLine("Could not connect to URL");
            }
        }
    }
}
